import { setupWebSocket } from '@/utils/websocket'
const state = {
  ws: null // WebSocket 实例
}

const mutations = {
  SET_WEBSOCKET(state, ws)
  {
    state.ws = ws
  }
}

const actions = {
  setupWebSocket({ commit }, { canvasFingerprint, vm }) // setupWebSocket(canvasFingerprint, vm) 不对
  {
    const ws = setupWebSocket(canvasFingerprint, vm) // 调用工具函数
    commit('SET_WEBSOCKET', ws) // 保存 WebSocket 实例到 Vuex
  }
}

const getters = {
  getWebSocket: (state) => state.ws // 获取 WebSocket 实例
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
